<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改教育经历')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-educate-edit" th:object="${basicEducate}">
            <input name="educateId" id="educateId" th:field="*{educateId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">员工姓名：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="houseId" type="hidden" th:field="*{userId}"  />
                        <input class="form-control" type="text" onclick="selectUserTree()" id="treeName" readonly="true" th:field="*{userName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学校名称：</label>
                <div class="col-sm-8">
                    <input name="schoolName" th:field="*{schoolName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">证书编号：</label>
                <div class="col-sm-8">
                    <input name="educateNo" id="educateNo" th:field="*{educateNo}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">学历：</label>
                <div class="col-sm-8">
                    <select name="educateName" class="form-control m-b" th:with="type=${@dict.getType('basic_educate_name')}">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{educateName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">学位：</label>
                <div class="col-sm-8">
                    <select name="educateDegree" class="form-control m-b" th:with="type=${@dict.getType('basic_educate_degree')}">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{educateDegree}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">专业：</label>
                <div class="col-sm-8">
                    <input name="educateMajor" class="form-control" type="text" th:field="*{educateMajor}">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">学历类型：</label>
                <div class="col-sm-8">
                    <select name="educateType" id="educateType" class="form-control m-b" th:with="type=${@dict.getType('basic_educate_type')}">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{educateType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">院校类型：</label>
                <div class="col-sm-8">
                    <select name="schoolType" class="form-control m-b" th:with="type=${@dict.getType('basic_school_type')}">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{schoolType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">入学时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startTime" class="form-control" placeholder="yyyy-MM-dd" type="text" th:field="*{startTime}">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">毕业时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endTime" class="form-control" placeholder="yyyy-MM-dd" type="text" th:field="*{endTime}">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上传附件：</label>
                <div class="col-sm-8">
                    <input accept="*/*" id="file" name="file" onchange="gen_size()" type="file">
                    <font color="red" class="pull-left mt10">
                        提示：请选择上传附件！
                    </font>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "basic/educate";
        $("#form-educate-edit").validate({
            onkeyup: false,
            rules:{
                educateNo:{
                    remote: {
                        url: prefix + "/checkUserEducateUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "educateId": function() {
                                return $("#educateId").val();
                            },
                            "userId": function() {
                                return $("#treeId").val();
                            },
                            "educateNo": function() {
                                return $("#educateNo").val();
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                }
            },
            messages: {
                "educateNo": {
                    remote: "教育经历已存在"
                }
            },
            focusCleanup: true
        });

        /* 选择人员 */
        function selectUserTree() {
            var options = {
                title: '选择员工',
                width: "380",
                url: ctx + "basic/user/selectTree",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            var treeType = body.find('#treeType').val();
            if(treeType == 'user'){
                var id = body.find('#treeId').val();
                var treeId = id.substring(id.indexOf('_') + 1, id.length);
                $("#treeId").val(treeId);
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }else{
                $.modal.alertError("请选择员工");
            }
        }

        function gen_size(){
            var file = document.getElementById("file").files[0];
            var size = file.size;
            if(size > 100 * 1024 * 1024){
                $.modal.alertError("超出最大限制：100M");
                return;
            }
        }

        function submitHandler() {
            if ($.validate.form()) {
                var formData = new FormData($('#form-educate-edit')[0]);
                $.operate.saveFile(prefix + "/edit", formData);
            }
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>